﻿using System;
using System.Collections.Generic;
using System.Data.Entity.Infrastructure;
using System.Data.Objects.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZBJF.Warranty.Common.Common;
using ZBJF.Warranty.Common.Enums.InsuranceWarranty;
using ZBJF.Warranty.Common.Enums.System;
using ZBJF.Warranty.Model;
using ZBJF.Warranty.Model.ViewModel.InsuranceWarranty;

namespace ZBJF.Warranty.BLL
{
    public partial class UploadFilesService
    {


        /// <summary>
        /// 上传的文件
        /// </summary>
        /// <param name="fileBelongTableName"></param>
        /// <param name="fileBelongTablePKID"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public UploadFiles Load(NeedUploadFileDataTableEnums fileBelongTableName, long fileBelongTablePKID, string fileName)
        {
            var fileBelongTableNameStr = fileBelongTableName.ToString();
            return LoadEntities(o => o.FileBelongTableName.Equals(fileBelongTableNameStr) && o.FileBelongTablePKID == fileBelongTablePKID && o.FileName.Equals(fileName)).FirstOrDefault();
        }

        /// <summary>
        /// 已经存在就重命名
        /// </summary>
        /// <param name="fileBelongTableName"></param>
        /// <param name="fileBelongTablePKID"></param>
        /// <param name="fileName"></param>
        /// <returns></returns>
        public bool Exist(NeedUploadFileDataTableEnums fileBelongTableName, long fileBelongTablePKID, string fileName)
        {
            var fileBelongTableNameStr = fileBelongTableName.ToString();
            return LoadEntities(o => o.FileBelongTableName.Equals(fileBelongTableNameStr) && o.FileBelongTablePKID == fileBelongTablePKID && o.FileName.Equals(fileName)).Any();

        }

        public IQueryable<UploadFiles> GetFiles(NeedUploadFileDataTableEnums fileBelongTableName, long fileBelongTablePKID)
        {
            var fileBelongTableNameStr = fileBelongTableName.ToString();
            return LoadEntities(o => o.FileBelongTableName.Equals(fileBelongTableNameStr) && o.FileBelongTablePKID == fileBelongTablePKID);
        }
    }
}
